﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web.Security;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using com.codebump;

public partial class TriBetic_TriBetic: System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["listid"] != null)
                Session["listid"] = Request.QueryString["listid"];
            else
                Session["listid"] = 123456; //

            if (Request.QueryString["dnis"] != null)
                Session["dnis"] = Request.QueryString["dnis"];
            else
                Session["dnis"] = "9727745296";

            if (Request.QueryString["servername"] != null)
                Session["servername"] = Request.QueryString["servername"];
            else
                Session["servername"] = "COGSQL";

            if (Request.QueryString["projectname"] != null)
                Session["projectname"] = Request.QueryString["projectname"];
            else
                Session["projectname"] = "TriBetic";
            if (Request.QueryString["campaignname"] != null)
                Session["campaignname"] = Request.QueryString["campaignname"];
            else
                Session["campaignname"] = "TriBetic";
            if (Request.QueryString["agentid"] != null)
                Session["agentid"] = Request.QueryString["agentid"];
            else
                Session["agentid"] = 66319;
            if (Request.QueryString["agentfirst"] != null)
                Session["agentfirst"] = Request.QueryString["agentfirst"];
            else
                Session["agentfirst"] = "TestFirst";
            if (Request.QueryString["agentlast"] != null)
                Session["agentlast"] = Request.QueryString["agentlast"];
            else
                Session["agentlast"] = "TestLast";

           Session["App"] = new DataAccess();
           ((DataAccess)Session["App"]).PutCallData("ScriptStart", "ScriptStart", System.DateTime.Now.ToString());
           ((DataAccess)Session["App"]).CommitCallData();

           Session["CInfo"] = true;   //set to false if going to test if customer information is entered/correct
            //The session variables are requested in the master page currently using the following syntax: Session["servername"] = Request.QueryString["servername"];
            //The page is loaded before the master page so if the code isn't in a control, it will currently error out.
            //((DataAccess)Session["App"]).ConnectInbound(Session["servername"].ToString(), Session["projectname"].ToString(), Session["campaignname"].ToString(), Session["dnis"].ToString(), Session["listid"].ToString());

           WebWizard.ActiveStepIndex = WebWizard.WizardSteps.IndexOf(this.Intro);
        }
        else
        {

        }


    }
    //POST LOGIC - For Step or Start pages
    //Add if statements as you add pages
    //For Next and Finish pages it is best to use the index in the if statements as below
    protected void WebWizard_NextButtonClick(object sender, WizardNavigationEventArgs e)
    {
        int page = WebWizard.ActiveStepIndex;
        if (page == WebWizard.WizardSteps.IndexOf(this.Intro))
        {
            return;
        }

        if (page == WebWizard.WizardSteps.IndexOf(this.MainOffer))
        {
            
            return;
        }
        if (page == WebWizard.WizardSteps.IndexOf(this.Upsells)) //post-logic for upsell pages
        {
            
                return;
            
        }
        if (page == WebWizard.WizardSteps.IndexOf(this.Information))
        {
            return;
        }
        if (page == WebWizard.WizardSteps.IndexOf(this.Disposition))
        {
            return;
        }
    }

    //POST LOGIC for disposition pages
    //this is for pages that contain a disposition button
    protected void WebWizard_FinishButtonClick(object sender, WizardNavigationEventArgs e)
    {

        int page = WebWizard.ActiveStepIndex;
        if (page == WebWizard.WizardSteps.IndexOf(this.Intro))
        {
            return;
        }
        if (page == WebWizard.WizardSteps.IndexOf(this.Information))
        {

            return;
        }
        if (page == WebWizard.WizardSteps.IndexOf(this.Disposition))
        {
            return;
        }


    }

    //PRE-LOGIC
    //Add if statements as needed for post-logic
    //You can use the Step ID name instead of the index as used in Next and Finish logic.
    protected void WebWizard_ActiveStepChanged(object sender, EventArgs e)
    {
        lblError.Visible = false;
        Session["CInfo"] = validateCustomer();
        if (WebWizard.ActiveStep.Title.ToString() != "Intro" && !(bool)Session["CInfo"])
        {
            lblError.Text = "Enter first and last name";
            lblError.Visible = true;
        }

        if (WebWizard.ActiveStep.Title.ToString() == "")
        {
           
        }
        if (WebWizard.ActiveStep.Title.ToString() == "Disposition")
        {
      

            //if ((bool)Session["CInfo"])
            if (RadioButtonListMainOffer.SelectedIndex > -1 && (bool)Session["CInfo"])
            {
                buildorder();

                //pnlDispoConfirm.Visible = false;
                //((DataAccess)Session["App"]).PutCallData("webtransfer", "");
                ((DataAccess)Session["App"]).PutCallData("webusercode", "I0"); //saleuse code
                ((DataAccess)Session["App"]).CommitOrder();
                ((DataAccess)Session["App"]).CommitCallData();
                Response.Redirect("../DispositionComplete.aspx");
            }
            else
            {
               WebWizard.ActiveStepIndex = WebWizard.WizardSteps.IndexOf(this.IsSale);
                if(validateCustomer())
                    lblError.Text = "Enter what was sold";
                else
               lblError.Text = "Enter first and last name";
               lblError.Visible = true;

            }
            return;
        }
        else
        {
        }

    }

    protected void btnSubmit_Click(object sender, System.EventArgs e)
    {
        lblError.Text = "";
        bool bCustValid = validateCustomer();
        /*bool bShipValid = validateShipping();
        bool bPmtValid = validatePayment();

        if (bCustValid) //If required data is valid, check if optional data is valid. If not, set bCustValid to invalid
        {
            bCustValid = submitOptionalData();
        }
        submitCustData(bCustValid, bShipValid);
        submitPmtInfo(bPmtValid);
        
        if (bCustValid && (bPmtValid))
        {
            if (!cbShipping.Checked || bShipValid)
            {
                Session["CInfo"] = true;
            }
            else
            {
                Session["CInfo"] = false;
            }
        }
        else
        {
            Session["CInfo"] = false;
        }
        */

        submitCustData(bCustValid, true);
        ((DataAccess)Session["App"]).CommitCallData();
        
    }

    ///***************************
    ///
    /*
    protected void ddlPaymentType_SelectedIndexChanged(object sender, EventArgs e)
    {
        Session["CInfo"] = false;
        
        if (ddlPaymentType.SelectedValue == "CC")
        {
            trCCNumber.Visible = true;
            trCCType.Visible = true;
            trCCExpDate.Visible = true;
            //trCCV.Visible = true;
            trECAccNum.Visible = false;
            trECBankName.Visible = false;
            trECCheckNum.Visible = false;
            trECRoutNum.Visible = false;
            trECAccType.Visible = false;
            trECAccHolder.Visible = false;
            tbAccHolder.Text = "";
            tbAccNum.Text = "";
            tbBankName.Text = "";
            tbRoutNum.Text = "";
            tbCheckNum.Text = "";
           
        }
        else if (ddlPaymentType.SelectedValue == "EC")
        {
            trCCNumber.Visible = false;
            trCCType.Visible = false;
            trCCExpDate.Visible = false;
            //trCCV.Visible = false;
            trECAccNum.Visible = true;
            trECBankName.Visible = true;
            trECCheckNum.Visible = true;
            trECRoutNum.Visible = true;
            trECAccType.Visible = true;
            trECAccHolder.Visible = true;
            tbCCNumber.Text = "";
            tbExpDate.Text = "";
        }
        else //They changed it from EC or CC to blank
        {
            trCCNumber.Visible = false;
            trCCType.Visible = false;
            trCCExpDate.Visible = false;
            //trCCV.Visible = false;
            trECAccNum.Visible = false;
            trECBankName.Visible = false;
            trECCheckNum.Visible = false;
            trECRoutNum.Visible = false;
            trECAccType.Visible = false;
            tbCCNumber.Text = "";
            tbExpDate.Text = "";
            tbAccHolder.Text = "";
            tbAccNum.Text = "";
            tbBankName.Text = "";
            tbRoutNum.Text = "";
            tbCheckNum.Text = "";
        }
        

    }
    */
/*
    protected void cbShipping_CheckedChanged(object sender, EventArgs e)
    {
        if (cbShipping.Checked)
        {

            trShipAddr.Visible = true;
            trShipAddr2.Visible = true;
            trShipCity.Visible = true;
            trShipState.Visible = true;
            trShipCountry.Visible = true;
            trShipZip.Visible = true;
            trShipLbl.Visible = true;
            trShipSearchZip.Visible = true;

        }
        else
        {
            trShipAddr.Visible = false;
            trShipAddr2.Visible = false;
            trShipCity.Visible = false;
            trShipState.Visible = false;
            trShipCountry.Visible = false;
            trShipZip.Visible = false;
            trShipLbl.Visible = false;
            trShipSearchZip.Visible = false;
        }
    }
    */
/*
    protected void btnSearchZip_Click(object sender, EventArgs e)
    {
        ValidateZip(tbZip.Text.ToUpper(), ddlCity, ddlState, ddlCountry);
        //if (cbShipping.Checked)
        //{
        //    if (ddlShipCountry.SelectedItem.Text == "CANADA")
        //    {
        //        ddlPaymentType.Items[2].Enabled = false;
        //    }
        //}
        //else if (ddlCountry.SelectedItem.Text == "CANADA")
        //{
        //    ddlPaymentType.Items[2].Enabled = false;
        //}
        //else
        //{
        //    ddlPaymentType.Items[2].Enabled = true;
        //}
    }
    */
/*
    protected void btnShipSearchZip_Click(object sender, EventArgs e)
    {
        ValidateZip(tbShipZip.Text.ToUpper(), ddlShipCity, ddlShipState, ddlShipCountry);
        //if (cbShipping.Checked)
        //{
        //    if (ddlShipCountry.SelectedItem.Text == "CANADA")
        //    {
        //        ddlPaymentType.Items[2].Enabled = false;
        //    }
        //    else
        //    {
        //        ddlPaymentType.Items[2].Enabled = true;
        //    }
        //}
    }
/*
    protected void ValidateZip(string strZip, DropDownList ddl_City, DropDownList ddl_State, DropDownList ddl_Country)
    {

        ddl_City.Items.Clear();
        ddl_State.Items.Clear();
        ddl_City.Enabled = true;
        ddl_State.Enabled = true;
        if (System.Text.RegularExpressions.Regex.IsMatch(strZip.ToUpper(), @"(^\d{5}$)|(^[ABCEGHJKLMNPRSTVXY]{1}\d{1}[A-Z]{1} +\d{1}[A-Z]{1}\d{1}$)"))
        {
            try
            {
                com.codebump.GeoPlaces g = new com.codebump.GeoPlaces();

                com.codebump.AuthenticationHeader authHeader = new com.codebump.AuthenticationHeader();
                authHeader.SessionID = "6JV2ZA4lgG1YRR+HG+JU27QWk9zI3rpRWY2iG2mzNPcdieEQXfQv0OUY0EZ+pOTxhwI1NCuF7b2oY+U/bozy0mhjFHmpaXvb";
                g.AuthenticationHeaderValue = authHeader;

                com.codebump.GeoPlaceDistance[] places = g.GetPlacesInside(strZip, "");

                for (int i = 0; i < places.Length; i++)
                {
                    com.codebump.GeoPlaceDistance place = places[i];
                    ListItem li = new ListItem(place.ToPlace, place.ToState + "," + place.ToPlace);
                    ddl_City.Items.Add(li);
                }

                ddl_State.Items.Add(ddl_City.SelectedItem.Value.Split(",".ToCharArray())[0]);
                
                //ddlCity.SelectedIndex = 0;

                if (System.Text.RegularExpressions.Regex.IsMatch(strZip.ToUpper(), @"(^[ABCEGHJKLMNPRSTVXY]{1}\d{1}[A-Z]{1} *\d{1}[A-Z]{1}\d{1}$)"))
                {
                    ddl_Country.SelectedValue = "CANADA";
                }
                else
                {
                    ddl_Country.SelectedValue = "USA";
                }

                if (ddl_City.Items.Count <= 0)
                {
                    ddl_City.Items.Add("No Cities Found");
                    ddl_State.Items.Add("No States Found");
                    ddl_City.Enabled = false;
                    ddl_State.Enabled = false;
                }
                else
                {
                    ddl_City.Items.Insert(0, "Select a City");
                    ddl_City.SelectedIndex = 0;
                    ddl_State.Enabled = false;
                }
            }
            catch
            {
                ddl_City.Items.Add("No Cities Found");
                ddl_State.Items.Add("No States Found");
                ddl_City.Enabled = false;
                ddl_State.Enabled = false;
            }
        }
        else
        {
            ddl_City.Items.Add("Invalid Zip");
            ddl_City.Enabled = false;
            ddl_State.Items.Add("Invalid Zip");
            ddl_State.Enabled = false;
        }
    }

    public DataAccess.CardType GetCardType(string cardType)
    {
        switch (cardType)
        {
            case "A":
                return DataAccess.CardType.AmericanExpress;
            case "V":
                return DataAccess.CardType.Visa;
            case "D":
                return DataAccess.CardType.Discover;
            case "M":
                return DataAccess.CardType.MasterCard;
            default:
                return DataAccess.CardType.Visa;
        }
    }
    /*
    public double GetOrderTotalPerItemShipping()
    {
        double BaseTotal = 0.00;
        double ShippingTotal = 0.00;
        for (int i = 0; i < (((DataAccess)Session["App"]).GetOrder()).Rows.Count; i++)
        {
            BaseTotal += Convert.ToDouble((Convert.ToDouble((((DataAccess)Session["App"]).GetOrder()).Rows[i]["BaseRevenue"])) * Convert.ToDouble((((DataAccess)Session["App"]).GetOrder()).Rows[i]["Quantity"]));
            ShippingTotal = ShippingTotal + Convert.ToDouble((Convert.ToDouble((((DataAccess)Session["App"]).GetOrder()).Rows[i]["SecondaryRevenue"])) * Convert.ToDouble((((DataAccess)Session["App"]).GetOrder()).Rows[i]["Quantity"]));
        }

        if (cbShipping.Checked)
        {
            if (ddlShipState.Items.Count > 0)   //error checking to make sure there is a state
            {
                if (ddlShipState.SelectedItem.Text == "IL")
                {
                    BaseTotal *= 1.07;
                }
            }
        }
        else
        {
            if (ddlState.Items.Count > 0)//error checking to make sure there is a state
            {
                if (ddlState.SelectedItem.Text == "IL")
                {
                    BaseTotal *= 1.07;
                }
            }
        }
        return Math.Round((BaseTotal + ShippingTotal), 2);
    }
     */
    /*
    public double GetRecurringPayment()
    {
        double secTotal = 0.00;
        DataTable productscomp = new DataTable();
        for (int i = 0; i < (((DataAccess)Session["App"]).GetOrder()).Rows.Count; i++)
        {

            //productscomp = ((DataAccess)Session["App"]).GetProducts("ProductID = " + ((DataAccess)Session["App"]).GetOrder().Rows[i]["ProductID"].ToString());
            productscomp = ((DataAccess)Session["App"]).GetProducts("ProductID", ((DataAccess)Session["App"]).GetOrder().Rows[i]["ProductID"].ToString());
            if (productscomp.Rows[0]["Group2"].ToString() == "3-pay")
            {
                secTotal += Convert.ToDouble(Convert.ToDouble(((DataAccess)Session["App"]).GetOrder().Rows[i]["BaseRevenue"]) * Convert.ToDouble(((DataAccess)Session["App"]).GetOrder().Rows[i]["Quantity"]));
            }

        }

        if (cbShipping.Checked)
        {
            if (ddlShipState.Items.Count > 0) //error checking to make sure there is a state
            {
                if (ddlShipState.SelectedItem.Text == "IL")
                {
                    secTotal *= 1.07;
                }
            }
        }
        else
        {
            if (ddlState.Items.Count > 0) //error checking to make sure there is a state
            {
                if (ddlState.SelectedItem.Text == "IL")
                {
                    secTotal *= 1.07;
                }
            }
        }
        return Math.Round(secTotal, 2);
    }

    */
    /*
    protected void btnFAQ_Click(object sender, EventArgs e)
    {
        btnFAQ.Text = "View FAQ";
        pnlWizard.Visible = false;

        if (pnlFAQ.Visible)
        {
            pnlFAQ.Visible = false;
            pnlWizard.Visible = true;
        }
        else
        {
            pnlFAQ.Visible = true;
            btnFAQ.Text = "Return to Script";
        }
    }
      */
    
    #region Validate customer info and write it to in-memory calldata table
    protected bool validateCustomer()
    {
        bool bCustValid = false;

        bCustValid = !(string.IsNullOrEmpty(tbFirstName.Text) ||
            string.IsNullOrEmpty(tbLastName.Text)            ); 
               /*   
            ||
      
            string.IsNullOrEmpty(tbAddr.Text) ||
            (tbAddr.Text == "PO BOX ") ||
            string.IsNullOrEmpty(tbZip.Text) ||
            string.IsNullOrEmpty(ddlCity.SelectedItem.Text) ||
            string.IsNullOrEmpty(ddlState.SelectedItem.Text) ||
            string.IsNullOrEmpty(ddlCountry.SelectedItem.Text)) &&
            (ddlCity.SelectedIndex > 0);
*/
        return bCustValid;
    }
    /*
    protected bool validateShipping()
    {
        bool bShipValid = false;

        bShipValid = !(string.IsNullOrEmpty(tbShipAddr.Text) ||
           (tbShipAddr.Text == "PO BOX ") ||
            //string.IsNullOrEmpty(tbShipaddr2.Text) ||
           string.IsNullOrEmpty(tbShipZip.Text) ||
           string.IsNullOrEmpty(ddlShipCity.SelectedItem.Text) ||
           ddlShipState.Items.Count <= 0 ||
           string.IsNullOrEmpty(ddlShipState.SelectedItem.Text) ||
           string.IsNullOrEmpty(ddlShipCountry.SelectedItem.Text)) &&
           (ddlShipCity.SelectedIndex > 0) &&
           (tbShipZip.Text.Length >= 5) &&
           (tbShipZip.Text.Length <= 7);

        return bShipValid;
    }
     */
    /*
    protected bool validatePayment()
    {
        bool pmtCheck = false;
        int yearval = Convert.ToInt32(DateTime.Today.ToString("yy"));
        switch (ddlPaymentType.SelectedIndex)
        {
            case 1:
                pmtCheck = !(string.IsNullOrEmpty(ddlCardType.SelectedItem.Text) ||
                    string.IsNullOrEmpty(tbCCNumber.Text) ||
                    //string.IsNullOrEmpty(tbCCV.Text) ||
                    string.IsNullOrEmpty(tbExpDate.Text) ||
                    (Convert.ToInt32(tbExpDate.Text.Substring(2, 2)) == yearval && Convert.ToInt32(tbExpDate.Text.Substring(0, 2)) < Convert.ToInt32(DateTime.Today.ToString("MM")))) &&
                    (Convert.ToInt32(tbExpDate.Text.Substring(2, 2)) >= yearval) &&
                    (Convert.ToInt32(tbExpDate.Text.Substring(2, 2)) <= (yearval + 10)) &&
                    (Convert.ToInt32(tbExpDate.Text.Substring(0, 2)) >= 1 && Convert.ToInt32(tbExpDate.Text.Substring(0, 2)) <= 12) &&
                    (((DataAccess)Session["App"]).IsValidCC(GetCardType(ddlCardType.SelectedValue), tbCCNumber.Text)) &&
                    tbExpDate.Text.Length == 4 &&
                    (System.Text.RegularExpressions.Regex.IsMatch(tbExpDate.Text, @"^[\d]+$"));
                break;
            case 2:
                pmtCheck = !(string.IsNullOrEmpty(tbBankName.Text) ||
                    string.IsNullOrEmpty(tbAccHolder.Text) ||
                    string.IsNullOrEmpty(tbAccNum.Text) ||
                    string.IsNullOrEmpty(tbRoutNum.Text) ||
                    string.IsNullOrEmpty(tbCheckNum.Text)) &&
                    (System.Text.RegularExpressions.Regex.IsMatch(tbAccNum.Text, @"^[\d]+$")) &&
                    (System.Text.RegularExpressions.Regex.IsMatch(tbRoutNum.Text, @"^[\d]+$")) &&
                    (System.Text.RegularExpressions.Regex.IsMatch(tbCheckNum.Text, @"^[\d]+$")) &&
                    ((DataAccess)Session["App"]).ValidateRoutingNumber(Convert.ToInt32(tbRoutNum.Text));
                break;
            default:
                pmtCheck = false;
                lblError.Text += "Please select a payment method<br/>";
                break;

        }
        return pmtCheck;

    }
      */
    protected void submitCustData(bool bCustValid, bool bShipValid)
    {
        if (bCustValid)
        {
            ((DataAccess)Session["App"]).PutCallData("firstname", tbFirstName.Text.Replace(",", ""));
            ((DataAccess)Session["App"]).PutCallData("lastname", tbLastName.Text.Replace(",", ""));
            /*

            ((DataAccess)Session["App"]).PutCallData("address1", tbAddr.Text.Replace(",", ""));
            if (!string.IsNullOrEmpty(tbAddr2.Text))
                ((DataAccess)Session["App"]).PutCallData("address2", tbAddr2.Text.Replace(",", ""));
            else
                ((DataAccess)Session["App"]).PutCallData("address2", "");
            ((DataAccess)Session["App"]).PutCallData("Zip", tbZip.Text.Replace(",", ""));
            ((DataAccess)Session["App"]).PutCallData("City", ddlCity.SelectedItem.Text.Replace(",", ""));
            ((DataAccess)Session["App"]).PutCallData("State", ddlState.SelectedItem.Text);
            ((DataAccess)Session["App"]).PutCallData("Country", ddlCountry.SelectedItem.Text);

            //this is what happens if the shipping info is not visible
            if (!cbShipping.Checked)
            {
                ((DataAccess)Session["App"]).PutCallData("ShipAddress1", tbAddr.Text.Replace(",", ""));
                if (!string.IsNullOrEmpty(tbAddr2.Text))
                    ((DataAccess)Session["App"]).PutCallData("ShipAddress2", tbAddr2.Text.Replace(",", ""));
                else
                    ((DataAccess)Session["App"]).PutCallData("ShipAddress2", "");
                ((DataAccess)Session["App"]).PutCallData("ShipZip", tbZip.Text.Replace(",", ""));
                ((DataAccess)Session["App"]).PutCallData("ShipCity", ddlCity.SelectedItem.Text.Replace(",", ""));
                ((DataAccess)Session["App"]).PutCallData("ShipState", ddlState.SelectedItem.Text);
                ((DataAccess)Session["App"]).PutCallData("ShipCountry", ddlCountry.SelectedItem.Text);
            }
            //this is what happens if the shipping info is visible
            else
            {
                if (bShipValid)
                {
                    ((DataAccess)Session["App"]).PutCallData("ShipAddress1", tbShipAddr.Text.Replace(",", ""));
                    if (!string.IsNullOrEmpty(tbShipAddr.Text))
                        ((DataAccess)Session["App"]).PutCallData("ShipAddress2", tbShipaddr2.Text.Replace(",", ""));
                    else
                        ((DataAccess)Session["App"]).PutCallData("ShipAddress2", "");
                    ((DataAccess)Session["App"]).PutCallData("ShipZip", tbShipZip.Text.Replace(",", ""));
                    ((DataAccess)Session["App"]).PutCallData("ShipCity", ddlShipCity.SelectedItem.Text.Replace(",", ""));
                    ((DataAccess)Session["App"]).PutCallData("ShipState", ddlShipState.SelectedItem.Text);
                    ((DataAccess)Session["App"]).PutCallData("ShipCountry", ddlShipCountry.SelectedItem.Text);
                }
                else
                {
                    lblError.Text += "Enter Valid Shipping Info<br/>";
                }
            }
        }
        //this else covers error checking
        else
        {
            if (tbAddr.Text == "PO BOX ")
            {
                lblError.Text += "Enter a PO BOX number <br/>";
            }
            else
            {
                if (ddlCity.Items.Count > 1 && ddlCity.SelectedIndex == 0)
                {
                    lblError.Text += "Select a City<br/>";
                }
                else
                {
                    lblError.Text += "Enter Valid Customer Data<br/>";
                }
            }
     */
        }

    }
    /*
    protected bool submitOptionalData()
    {
        bool bOpt = true;

        if ((!string.IsNullOrEmpty(tbPhone.Text)) && ((tbPhone.Text.Length != 10) || !(System.Text.RegularExpressions.Regex.Match(tbPhone.Text, @"^[1-9]\d{2}[1-9]\d{6}$").Success)))
        {
            lblError.Text += "Invalid Phone<br/>";
            bOpt = false;
        }
        else
        {
            if (!string.IsNullOrEmpty(tbPhone.Text))
                ((DataAccess)Session["App"]).PutCallData("PrimaryPhone", tbPhone.Text);
        }

        if ((!string.IsNullOrEmpty(tbEmail.Text)) && !((DataAccess)Session["App"]).IsValidEmail(tbEmail.Text))
        {
            lblError.Text += "Invalid Email<br/>";
            bOpt = false;
        }
        else
        {
            if (!string.IsNullOrEmpty(tbEmail.Text))
                ((DataAccess)Session["App"]).PutCallData("Email", tbEmail.Text);
        }

        return bOpt;
    }
     */
    /*
    protected void submitPmtInfo(bool bPmtValid)
    {
        if (bPmtValid)
        {
            ((DataAccess)Session["App"]).PutCallData("PaymentType", ddlPaymentType.SelectedItem.Value);

            switch (ddlPaymentType.SelectedIndex)
            {
                case 1: //Credit Card
                    ((DataAccess)Session["App"]).PutCallData("CCType", ddlCardType.SelectedItem.Value);
                    ((DataAccess)Session["App"]).PutCallData("CCNumber", ((DataAccess)Session["App"]).EnryptData(tbCCNumber.Text));
                    //((DataAccess)Session["App"]).PutCallData("CCV", ((DataAccess)Session["App"]).EnryptData(tbCCV.Text));
                    ((DataAccess)Session["App"]).PutCallData("CCExpDate", ((DataAccess)Session["App"]).EnryptData((tbExpDate.Text.Substring(0, 2) + "/" + tbExpDate.Text.Substring(2, 2))));
                    break;
                case 2: //E-Check
                    ((DataAccess)Session["App"]).PutCallData("ECBankName", tbBankName.Text.Replace(",", ""));
                    ((DataAccess)Session["App"]).PutCallData("ECAccHolder", tbAccHolder.Text.Replace(",", ""));
                    ((DataAccess)Session["App"]).PutCallData("ECAccNumber", tbAccNum.Text);
                    ((DataAccess)Session["App"]).PutCallData("ECRoutingNumber", tbRoutNum.Text);
                    ((DataAccess)Session["App"]).PutCallData("ECCheckNumber", tbCheckNum.Text);
                    ((DataAccess)Session["App"]).PutCallData("ECAccType", ddlAccType.SelectedItem.Text);
                    break;
            }
        }
        else
        {
            lblError.Text += "Invalid Payment Info<br/>";
        }
    }
     */
    #endregion Validate customer info and write it to in-memory calldata table
    protected void tbFirstName_TextChanged(object sender, EventArgs e)
    {

    }
    protected void buildorder()
    {

       
        ((DataAccess)Session["App"]).GetOrder().Rows.Clear();

        if (RadioButtonListMainOffer.SelectedIndex == 1)
        {

            ((DataAccess)Session["App"]).PutOrderItem(417, 1);    //I need to know 417 taken from Voicenetfors/ webproducts
        }
        if (RadioButtonListMainOffer.SelectedIndex == 2)
        {

            ((DataAccess)Session["App"]).PutOrderItem(420, 1);    
        }
        if (RadioButtonListMainOffer.SelectedIndex == 3)
        {
            ((DataAccess)Session["App"]).PutOrderItem(421, 1);   
        }
        if (RadioButtonListUpsell.SelectedIndex == 1)
        {

            ((DataAccess)Session["App"]).PutOrderItem(418, 1);  
        }
        if (RadioButtonListUpsell.SelectedIndex == 2)
        {

            ((DataAccess)Session["App"]).PutOrderItem(419, 1);    
        }
    }



    protected void RadioButtonListMainOffer_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (RadioButtonListMainOffer.SelectedIndex > -1)
        {
            Label2.Visible = true;
            RadioButtonListUpsell.Visible = true;
            RadioButtonReset.Visible = true;
        }
        else
        {
            Label2.Visible = false;
            RadioButtonListUpsell.Visible = false;
            RadioButtonListUpsell.SelectedIndex = -1;
        }
        
    }


    protected void RadioButtonReset_CheckedChanged(object sender, EventArgs e)
    {
        Label2.Visible = false;
        RadioButtonListUpsell.Visible = false;
        RadioButtonListUpsell.SelectedIndex = -1;
        RadioButtonListMainOffer.SelectedIndex = -1;
        RadioButtonReset.Checked = false;
        RadioButtonReset.Visible = false;


    }
}
